<?PHP	//header
include('config/config.php');
include('php/header.php');
require "php/functions.php";
?>        

<?PHP	//Connect to database
	$conn = mysql_connect($cfg["connection"]["host"], $cfg["connection"]["userName"], $cfg["connection"]["password"]) 
		or die ('Error Cannot Connect to MySQL');
	@mysql_select_db($cfg["connection"]["database"]) or die( "Unable to select database");
	session_start();
	if (isset($_SESSION['checkbox_shopLocation']) && is_array($_SESSION['checkbox_shopLocation'])) {
//			println($_POST['checkbox_shopLocation'][0]);
		$column_name = $cfg["tbl_shopLocation"]["shopID"];
		$column_targetVal = $_SESSION['checkbox_shopLocation'][0]; //only consider 1st checkbox
		$tbl_name = $cfg["tbl"]["shopLocation"];
		$sql = "SELECT * FROM $tbl_name WHERE $column_name = $column_targetVal";
		$result = mysql_query($sql) or die (mysql_error());
		$row = mysql_fetch_array($result);
		$shopname = $row[$cfg["tbl_shopLocation"]["shopID"]];
		$location = $row[$cfg["tbl_shopLocation"]["location"]];
		$address = $row[$cfg["tbl_shopLocation"]["address"]];
	}
?>



<h2>Product Update</h2> 
		<?PHP
			if(isset($_POST['shopname']))
			{
				$shopname = $_POST['shopname'];
				$address = $_POST['add'];
				$location = $_POST['loc'];
				
				$tbl_name = $cfg["tbl"]["shopLocation"];
				$query = "INSERT INTO $tbl_name (shopId, location, address) 
						VALUES('".$shopname."', '".$location."', '".$address."')
						ON DUPLICATE KEY UPDATE shopId = '".$shopname."',  location = '".$location."', address = '".$address."'";
				$result = mysql_query($query);

				if($result)	echo("<div class=\"valid_box\">Shop Details Successfully Updated</div>");
				else echo("<div class=\"error_box\">Update Shop Details Failed</div>");
			}	
		?>
         <div class="form">
         <form action="<?PHP $_PHP_SELF_?>" method="post" id="ShopAdding" class="niceform">
                <fieldset>
                    <dl>
                        <dt><label for="email">Shop ID:</label></dt>
                        <dd><?PHP echo "<input type=\"text\" name=\"shopname\" size=\"56\" style=\"font-style: italic\" value=\"$shopname\" readonly />" ?></dd>
                    </dl>
                    <dl>
                        <dt><label for="password">Location:</label></dt>
                        <dd><?PHP echo "<input type=\"text\" name=\"loc\" size=\"54\" value=\"$location\"/>" ?></dd>
                    </dl>
                    <dl>
                        <dt><label for="password">Address:</label></dt>
                        <dd><?PHP echo "<input type=\"text\" name=\"add\" size=\"54\" value=\"$address\"/>" ?></dd>
                    </dl>
                    <dl>
                        <dt><label></label></dt>
                        <dd>
                            <input type="checkbox" name="interests[]" id="" value="" checked /><label class="check_label">I agree to the <a href="#">terms &amp; conditions</a></label>
                        </dd>
                    </dl>
                    
                     <dl class="submit">
                    <input type="submit" name="submit" id="submit" value="Submit" />
                     </dl>  
                </fieldset>       
         </form>
         </div>  

<div class="pagination">
<?PHP	//footer
include('php/footer.php');
?>
<?PHP
		// if (isset($_POST['checkbox_shopLocation']) && is_array($_POST['checkbox_shopLocation']) ){
			// foreach($_POST['checkbox_shopLocation'] as $inBarcode)
				// echo "<tr>".$inBarcode."</tr>";
		// }
?>